import {Injectable} from '@angular/core';
import {HttpService} from '../../../lib/service/http.service';
import {adSystemApiUrl} from '../../../../config/api';

@Injectable()
export class DeliveryManageService {

  constructor(private httpService: HttpService) {
  }

  // 添加运费模板
  addExpressTemp(data: any) {
    const url = `${adSystemApiUrl}/v1/member/express_template/add`;
    return this.httpService.httpPostAuth(url,data).map(data => data);
  }

  // 获取运费模板列表
  getExpressTempList(applet_uuid: string, page = 1, pageSize = 999) {
    const url = `${adSystemApiUrl}/v1/member/express_template/list?applet_uuid=${applet_uuid}&page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(data => data);
  }

  // 获取运费模板详情
  getExpressTempDetail(express_template_id: number) {
    const url = `${adSystemApiUrl}/v1/member/express_template/${express_template_id}/info`;
    return this.httpService.httpGetAuth(url).map(data => data);
  }

  // 编辑运费模板
  editExpressTemp(data) {
    const url = `${adSystemApiUrl}/v1/member/express_template/edit`;
    return this.httpService.httpPostAuth(url,data).map(data => data);
  }

  // 删除模板
  delExpressTemp(id: number) {
    const url = `${adSystemApiUrl}/v1/member/express_template/${id}/del`;
    return this.httpService.httpPostAuth(url,{}).map(data => data);
  }

  //  获取运费模板内容列表
  getExpressTempValList(express_template_id: number,type?: string, order_sort = 'asc', page = 1, pageSize = 999) {
    let exType = type||'';
    const url = `${adSystemApiUrl}/v1/member/express_template_value/list?express_template_id=${express_template_id}&type=${exType}&order_sort=${order_sort}&page=${page}&pageSize=${pageSize}`;
    return this.httpService.httpGetAuth(url).map(data => data);
  }

  // 获取运费模板内容详情
  getExpressTempValDetail(id: number) {
    const url = `${adSystemApiUrl}/v1/member/express_template_value/${id}/info`;
    return this.httpService.httpGetAuth(url).map(data => data);
  }

  // 添加运费模板内容
  addExpressTempVal(data) {
    const url = `${adSystemApiUrl}/v1/member/express_template_value/add`;
    return this.httpService.httpPostAuth(url,data).map(data => data);
  }

  // 编辑运费模板内容
  editExpressTempVal(data) {
    const url = `${adSystemApiUrl}/v1/member/express_template_value/edit`;
    return this.httpService.httpPostAuth(url,data).map(data => data);
  }

  // 删除运费模板内容
  delExpressTempVal(id: number) {
    const url = `${adSystemApiUrl}/v1/member/express_template_value/${id}/del`;
    return this.httpService.httpPostAuth(url,{}).map(data => data);
  }
}
